{include file='common/_meta' /}

<body>
<div class="container">

	<form class="layui-form" action="" lay-filter="form" id="form-article">

		<div class="layui-row">
		  	<div class="layui-form-item layui-col-sm6">
		    	<label class="layui-form-label"><span class="custom-color-red">*</span>公司名称：</label>
		    	<div class="layui-input-block">
			     	<input type="text" name="company_name" value="" placeholder="公司名称" autocomplete="off" class="layui-input" lay-verify="required">
		    	</div>
		 	</div>
	 	</div>

	 	<div class="layui-row">
		  	<div class="layui-form-item layui-col-sm6">
		    	<label class="layui-form-label">公司联系人：</label>
		    	<div class="layui-input-block">
			     	<input type="text" name="user_name" value="" placeholder="公司联系人" autocomplete="off" class="layui-input">
		    	</div>
		 	</div>
	 	</div>

	 	<div class="layui-row">
		  	<div class="layui-form-item layui-col-sm6">
		    	<label class="layui-form-label">联系电话：</label>
		    	<div class="layui-input-block">
			     	<input type="text" name="channel_phone" value="" placeholder="联系电话" autocomplete="off" class="layui-input">
		    	</div>
		 	</div>
	 	</div>

       <!--  <div class="layui-row">
            <div class="layui-form-item layui-col-sm6">
                <label class="layui-form-label"><span class="custom-color-red">*</span>短信单价：</label>
                <div class="layui-input-block">
                    <input type="text" name="sms_price" value="" placeholder="短信单价" autocomplete="off" class="layui-input" onblur ="IWS_CheckDecimal(this)" onkeyup="IWS_CheckDecimal(this)" lay-verify="required">
                </div>
            </div>
        </div> -->
		<div class="layui-row">
			<div class="layui-form-item layui-col-sm6">
			    <label class="layui-form-label">验证IP：</label>
			    <div class="layui-input-block">
			      	<input type="radio" name="off_ip" value="0" title="验证">
			      	<input type="radio" name="off_ip" value="1" title="不验证" checked>
			      	<p>【注意】选择验证，ip必填</p>
			    </div>
			</div>
		</div>
		<div class="layui-row">
		  	<div class="layui-form-item layui-col-sm6">
		    	<label class="layui-form-label">ip白名单：</label>
		    	<div class="layui-input-block">
			     	<input type="text" name="ip" value="" placeholder="ip白名单" autocomplete="off" class="layui-input">
		 	   		<p>【注意】多个ip请用","隔开</p>
		    	</div>
		 	</div>
	 	</div>
		<div class="layui-row">
		  	<div class="layui-form-item layui-col-sm6">
		    	<label class="layui-form-label">回调接收地址：</label>
		    	<div class="layui-input-block">
			     	<input type="text" name="back_url" value="" placeholder="回调接收地址" autocomplete="off" class="layui-input">
		    	</div>
		 	</div>
	 	</div>

        <div class="layui-row">
            <div class="layui-form-item layui-col-sm6">
                <label class="layui-form-label">帐号类型：</label>
                <div class="layui-input-block">
                    <select name="channel_type" lay-filter="channel_type">
                        <option value="HTTP" selected>HTTP</option>
                    </select>
                </div>
            </div>
        </div>
		<div class="layui-row">
		  	<div class="layui-form-item">
			    <div class="layui-input-block">
			     	<button class="layui-btn" lay-submit lay-filter="formDemo">提交</button>
			     	<input class="layui-btn layui-btn-primary" type="reset" value="重置">
			    </div>
		  	</div>
	  	</div>

	</form>

</div>
{include file="common/_footer"}

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
layui.use('form', function() {

	var layer = layui.layer;
	var form  = layui.form;

	//监听提交
	form.on('submit(formDemo)', function(data) {

		$.ajax({
		    type : "POST",
		    url  : "{:url('Channel/addChild')}",
		    data : $("#form-article").serialize(),
		    success : function(data) {

		        if(data.code == 1) {

		            layer.msg(data.msg,{
		                    icon:2,
		                    skin:'layer-ext-moon'
		                });
	            } else {
	            	layer.confirm('添加成功；是否继续添加渠道登录账号?', function(index){
					    parent.layer.closeAll();
					    parent.layer.open({
		                    type: 2,
		                    title: '添加渠道登录账户',
		                    area: ['100%', '100%'],
		                    content: '{:url('Channel/addUser')}'
		                });
					},function(index){
						layer.alert("1.CID："+data.msg+"<br>2.加密KEY:请联系平台管理员<br>3.需变更为cmpp账户，请联系平台管理员<br>4.创建的账户支持http对接，对接文档请联系平台管理员。", function(index){
							parent.layer.closeAll();
							parent.location.reload();
						});
					});

					$("input[type=reset]").click();
	            }
		    },
		    error : function(e) {

		        layer.msg('新增错误', {icon: 5,time:3000});
		    }
		});

		return false;
	});

	// 监听渠道账号类型
	form.on('select(channel_type)', function(data) {

	  	if (data.value == 'CMPP') {

	  		$('#is-cmpp').removeClass('layui-hide');
	  	} else {

	  		$('#is-cmpp').addClass('layui-hide');
	  	}

		form.render();
	});

});
/*验证金额*/
function IWS_CheckDecimal(obj) {
    var temp = /^\d+\.?\d{0,5}$/;
    if (temp.test(obj.value)) {
    } else {
        obj.value = obj.value.substr(0, obj.value.length - 1);
        IWS_CheckDecimal(obj);
    }
}
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>